package jp.sourceforge.akjrcp.dropsomething2.psp;

import jp.sourceforge.akjrcp.dropsomething2.Setting;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

public class PSPOptionDialog extends Dialog{

	Setting setting;
	private boolean editable;
	private PSPOptionEditor editor;
	protected PSPOptionDialog(Shell parentShell,Setting setting,boolean editable) {
		super(parentShell);
		this.setting=setting;
		this.editable=editable;
	}

	 protected Control createDialogArea(Composite parent) {
		 editor = new PSPOptionEditor();
		 editor.setNewMode(false);//edit only
		 editor.setDirMode(true);
		 Composite composite=editor.createControls(parent);
		 editor.setParameters(setting.getParameters());
		 if(!editable){
			 editor.setEditable(false);
			
		 }
		 return composite;
	 }
	
	
	 protected void createButtonsForButtonBar(Composite parent) {
		 if(editable){
		  createButton(
			      parent,
			      IDialogConstants.OK_ID,
			      IDialogConstants.OK_LABEL,
			      true);
		 }
		    createButton(
		      parent,
		      IDialogConstants.CLOSE_ID,
		      IDialogConstants.CLOSE_LABEL,
		      true);
		  
		  }
	 
	 protected void buttonPressed(int id) {
		   
		    if (id == IDialogConstants.OK_ID) {
		      //update settings
		    	setting.setParameters(editor.getParameters());
		    }
		    setReturnCode(id);
		    close();
		    super.buttonPressed(id);
		  }

}
